package day05;

import java.util.Arrays;
import java.util.Random;

public class ArrayDemo {
    public static void main(String[] args) {
        /*
        int[] a  = new int[5];
        double[] d = new double[10];
        boolean[] b = new boolean[26];


        int[] arr1 = new int[3];
        int[] arr2 = new int[]{1,2,3};
        int[] arr3 = {4,5,6};

        int arr[]  = new int[3];
        System.out.println("数组的长度为"+arr.length);
        System.out.println("数组的第一个元素为"+arr[0]);
        arr[0]=100;
        arr[1]=200;
        arr[2]=300;
        System.out.println(arr[2]);
        System.out.println(arr[arr.length-1]);

         */
        Random rand = new Random();

        int[] arr = new int[10];
        for (int i = 0;i<arr.length;i++){
            arr[i]=rand.nextInt(100);
            System.out.println(arr[i]);
        }
        int[] a = {10,20,30,40,50};
        int[] b = new int[6];
        System.arraycopy(a,1,b,0,4);
        for (int i = 0; i < b.length; i++){
            System.out.println(b[i]);
        }
        //数组复制
        //a 源数组
        //c 目标数组
        //10 目标数组长度
        //若长度小于源数组长度，则截取源数组前10个元素 末尾截掉
        //若长度大于源数组长度，则用0填充
        int[] c = Arrays.copyOf(a,10);
        for (int i = 0; i < c.length; i++){
            System.out.println(c[i]);
        }

    }
}
